package com.eco.schedule;

import com.eco.controller.LightController;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

@EnableScheduling
@Lazy(false)
@Component
/* loaded from: newfishway-1.0.0-SNAPSHOT.jar:BOOT-INF/classes/com/eco/schedule/LightScheduleTask.class */
public class LightScheduleTask implements SchedulingConfigurer {
    private static final Logger log = LoggerFactory.getLogger((Class<?>) LightScheduleTask.class);

    @Autowired
    private LightController lightController;

    @Value("${lamplight.start}")
    private String lightStart;

    @Value("${lamplight.end}")
    private String lightEnd;

    @Value("${lamplight.DO}")
    private String doNum;
    private static final String ON_COMMAND_LIGHT = "00 00 00 00 00 06 FF 05 00 66 FF 00";
    private static final String OFF_COMMAND_LIGHT = "00 00 00 00 00 06 FF 05 00 66 00 00";
    private String onCron;
    private String offCron;

    @Override // org.springframework.scheduling.annotation.SchedulingConfigurer
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        if (!"0".equals(this.lightStart)) {
            scheduledTaskRegistrar.addTriggerTask(new Runnable() { // from class: com.eco.schedule.LightScheduleTask.1
                @Override // java.lang.Runnable
                public void run() {
                    LightScheduleTask.this.lightController.order2Knd("in", "on8");
                    LightScheduleTask.log.info("定时打开进口补光灯成功");
                    LightScheduleTask.this.lightController.order2Knd("out", "on1");
                    LightScheduleTask.log.info("定时打开出口补光灯成功");
                }
            }, new Trigger() { // from class: com.eco.schedule.LightScheduleTask.2
                @Override // org.springframework.scheduling.Trigger
                public Date nextExecutionTime(TriggerContext triggerContext) {
                    if (StringUtils.isEmpty(LightScheduleTask.this.onCron)) {
                        CronTrigger cronTrigger = new CronTrigger("0 0 " + LightScheduleTask.this.lightStart + " * * ?");
                        Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext);
                        return nextExecutionTime;
                    }
                    CronTrigger cronTrigger2 = new CronTrigger(LightScheduleTask.this.onCron);
                    Date nextExecutionTime2 = cronTrigger2.nextExecutionTime(triggerContext);
                    return nextExecutionTime2;
                }
            });
        }
        if (!"0".equals(this.lightEnd)) {
            scheduledTaskRegistrar.addTriggerTask(new Runnable() { // from class: com.eco.schedule.LightScheduleTask.3
                @Override // java.lang.Runnable
                public void run() {
                    LightScheduleTask.this.lightController.order2Knd("in", "off8");
                    LightScheduleTask.log.info("定时关闭进口灯带成功");
                    LightScheduleTask.this.lightController.order2Knd("out", "off1");
                    LightScheduleTask.log.info("定时关闭出口灯带成功");
                }
            }, new Trigger() { // from class: com.eco.schedule.LightScheduleTask.4
                @Override // org.springframework.scheduling.Trigger
                public Date nextExecutionTime(TriggerContext triggerContext) {
                    if (StringUtils.isEmpty(LightScheduleTask.this.offCron)) {
                        CronTrigger cronTrigger = new CronTrigger("0 0 " + LightScheduleTask.this.lightEnd + " * * ?");
                        Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext);
                        return nextExecutionTime;
                    }
                    CronTrigger cronTrigger2 = new CronTrigger(LightScheduleTask.this.offCron);
                    Date nextExecutionTime2 = cronTrigger2.nextExecutionTime(triggerContext);
                    return nextExecutionTime2;
                }
            });
        }
    }

    public void setOnCron(String onCron) {
        log.info("原来的onCron：" + this.onCron + "更新后的onCron：" + onCron);
        this.onCron = onCron;
    }

    public String getOnCron() {
        return this.onCron;
    }

    public void setOffCron(String offCron) {
        log.info("原来的offCron：" + this.offCron + "更新后的offCron：" + offCron);
        this.offCron = offCron;
    }

    public String getOffCron() {
        return this.offCron;
    }
}